package net.asrsmid.invoker.rs;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author Chen WANG
 * @version 1.0
 * @created 05-mai-2011 11:53:11
 */
public class DeviceInformationBuilder {
	private Map<String, String> deviceInfoMap;

	public DeviceInformationBuilder() {
		deviceInfoMap = new HashMap<String, String>();
	}

	/**
	 * 
	 * @param paramName
	 * @param paramValue
	 */
	public void addDeviceInfomation(String paramName, String paramValue){
		deviceInfoMap.put(paramName, paramValue);
	}

	/**
	 * 
	 * @param deviceInfoMap
	 */
	public void setDeviceInformation(DeviceInformation deviceInfo){
		this.deviceInfoMap = null;
		this.deviceInfoMap = deviceInfo.getDeviceInfoMap();
	}

	/**
	 * @return
	 */
	public String buildDeviceInfomationString(){
		StringBuffer sb = new StringBuffer();
		sb.append("<DeviceInfo>");
		
		Iterator<Entry<String, String>> it = deviceInfoMap.entrySet().iterator();
		while(it.hasNext()) {
			Entry<String, String> e = it.next();
			String paramName = e.getKey();
			String paramValue = e.getValue();
			
			sb.append("<").append(paramName).append(">");
			sb.append(paramValue);
			sb.append("</").append(paramName).append(">");
		}
		
		sb.append("</DeviceInfo>");
		
		return sb.toString();
	}
}